package com.example.electronicmall.controller;

import java.util.List;

import com.example.electronicmall.entity.ItemEntity;
import com.example.electronicmall.service.ItemService;
import com.example.electronicmall.to.ItemTo;
import com.example.electronicmall.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author mwh
 * @email 1062966353@qq.com
 * @date 2022-12-02 14:48:53
 */
@RestController
@RequestMapping("/item")
public class ItemController {
    @Autowired
    private ItemService itemService;

    @PostMapping("/save")
    public R saveItem(ItemTo itemTo){
        itemService.saveItem(itemTo);
        return R.ok().setData("商品添加成功");
    }

    @PostMapping("/query")
    public R listItemsByShopId(Integer shopId){
        List<ItemEntity> list = itemService.listItemsByShopId(shopId);
        return R.ok().setData(list);
    }

    @PostMapping("/queryAll")
    public R listAllItemsByShopId(Integer shopId){
        List<ItemTo> list = itemService.listAllItemsByShopId(shopId);
        return R.ok().setData(list);
    }

    @PostMapping("/up")
    public void upItem(Integer itemId){
        itemService.upItem(itemId);
    }

    @PostMapping("/down")
    public void downItem(int itemId){
        itemService.downItem(itemId);
    }
}
